This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.

library(car)
Warning: package ‘car’ was built under R version 4.3.3
Loading required package: carData
Warning: package ‘carData’ was built under R version 4.3.2

Attaching package: ‘car’

The following object is masked from ‘package:dplyr’:

    recode
df <- read.csv("Data/df_clean_more_features.csv")

getvar <- function()

dfuk <- df[df$cntry == "United Kingdom", ]
dftotuk %>% 
  select(gndr, weighta, fltdpr) %>% 
  mutate(gndr = factor(gndr, levels = c(1, 2), labels = c("Male", "Female"))) %>% 
  t.test(data = ., weighta ~ gndr)

    Welch Two Sample t-test

data:  weighta by gndr
t = 18.571, df = 1296.6, p-value < 2.2e-16
alternative hypothesis: true difference in means between group Male and group Female is not equal to 0
95 percent confidence interval:
 12.92829 15.98233
sample estimates:
  mean in group Male mean in group Female 
            82.34348             67.88817 
library(effsize)
cohen.d(df$weighta, df$gndr)

Cohen's d

d estimate: 1.027161 (large)
95 percent confidence interval:
    lower     upper 
0.9115384 1.1427840 
cohen.d(fem, mal)

Cohen's d

d estimate: -1.027161 (large)
95 percent confidence interval:
     lower      upper 
-1.1427840 -0.9115384 
mal <- dfmale[, "weighta"]
Error: unexpected symbol in:
""
mal <- dfmale[, "weighta"
df <- dftotuk[c("gndr", "weighta", "fltdpr")]

df$gndr <- factor(df$gndr, levels = c(1, 2), labels = c("Male", "Female"))

df %>% 
  group_by(gndr) %>% 
  summarise(n())

ggplot(data = df, aes(x = weighta, fill = gndr)) + geom_area(stat = "density", alpha = 0.5) + scale_fill_manual(values = c("Female" = "green", "Male" = "blue"))

cor(df$weighta, df$fltdpr)
[1] -0.003393421

Levene’s Test of homogeneity

leveneTest(data = df, weighta ~ gndr)
Levene's Test for Homogeneity of Variance (center = median)
        Df F value Pr(>F)
group    1  0.3674 0.5445
      1305               
dfmale <- dfuk[dfuk$gndr == "Male", ]
dffemale <- dfuk[dfuk$gndr == "Female", ]

dfuk
#Call ggplot
library(ggplot2)

#Make the plot
ggplot(data = dfmale, aes(x = cgtsmok)) + 
  geom_histogram()

shapiro.test(dfmale$cgtsmok)

dfpt <- read.csv('ess_allyr_multi.csv')
unique(dfpt$name)
 [1] "ESS1e06_7"    "ESS2e03_6"    "ESS3e03_7"    "ESS4e04_6"    "ESS5e03_5"    "ESS6e02_6"    "ESS7e02_3"   
 [8] "ESS8e02_3"    "ESS9e03_2"    "ESS10e03_2"   "ESS10SCe03_1" "ESS11e02"    
df <- dfpt %>% 
  mutate(name = case_when(
    name == "ESS1e06_7" ~ "2002",
    name == "ESS2e03_6" ~ "2004",
    name == "ESS3e03_7" ~ "2006",
    name == "ESS4e04_6" ~ "2008",
    name == "ESS5e03_5" ~ "2010",
    name == "ESS6e02_6" ~ "2012",
    name == "ESS7e02_3" ~ "2014",
    name == "ESS8e02_3" ~ "2016",
    name == "ESS9e03_2" ~ "2018",
    name == "ESS10e03_2" ~ "2020",
    name == "ESS11e02" ~ "2023"
  ))
dfhappy <- df %>% 
  select(name, happy) %>% 
  filter(happy <= 10) %>% 
  group_by(name, happy) %>% 
  summarise(qty = n(), .groups = "drop") %>% 
  group_by(name) %>% 
  mutate(perc = round((qty / sum(qty)) * 100, 1))
  #mutate(perc = mutate(qty/sum(qty)) *100)

dfhappy
dfhappy2 <- df %>% 
  select(name, happy) %>% 
  filter(happy <= 10) %>% 
  group_by(name, happy) %>% 
  summarise(qty = n(), .groups = "drop") %>% 
  group_by(name) %>% 
  mutate(perc = round((qty / sum(qty)) * 100, 1)) %>% 
  mutate(accum_freq = cumsum(perc)) %>% 
  mutate(accum_freq = ifelse(row_number() == n(), 100, accum_freq)) # Set last row to 100
  
dfhappy2
ggplot(dfhappy, aes(x = happy, y = perc, color = name, group = name)) +
  geom_line(size = 1) + # Lines for each year
  geom_point(size = 2) + # Points for better visibility
  labs(
    title = "Distribution of Happiness Scores by Year",
    x = "Happiness Score",
    y = "Percentage",
    color = "Year"
  ) +
  scale_x_continuous(breaks = 0:10) + # Show all happiness values on x-axis
  theme_minimal()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
This warning is displayed once every 8 hours.
Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated.

library(plotly)
Warning: package ‘plotly’ was built under R version 4.3.3
Registered S3 method overwritten by 'data.table':
  method           from
  print.data.table     

Attaching package: ‘plotly’

The following object is masked from ‘package:ggplot2’:

    last_plot

The following object is masked from ‘package:igraph’:

    groups

The following object is masked from ‘package:stats’:

    filter

The following object is masked from ‘package:graphics’:

    layout
# Interactive Plot with Plotly

plot <- dfhappy %>%
  plot_ly(
    x = ~happy,
    y = ~perc,
    color = ~name,
    type = 'scatter',
    mode = 'lines+markers',
    text = ~paste("Year:", name, "<br>Happy:", happy, "<br>Percentage:", perc, "%")
  ) %>%
  layout(
    title = "Distribution of Happiness Scores by Year",
    xaxis = list(title = "Happiness Score", tickvals = 0:10),
    yaxis = list(title = "Percentage"),
    legend = list(title = list(text = "Year"))
  )

plot
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
plot <- dfhappy %>%
  plot_ly(
    x = ~happy,
    y = ~perc,
    color = ~name,
    type = 'scatter',
    mode = 'lines',
    fill = 'tonexty', # Fills area below the line
    text = ~paste("Year:", name, "<br>Happy:", happy, "<br>Percentage:", perc, "%")
  ) %>%
  layout(
    title = "Distribution of Happiness Scores by Year",
    xaxis = list(title = "Happiness Score", tickvals = 0:10),
    yaxis = list(title = "Percentage"),
    legend = list(title = list(text = "Year"))
  )

plot
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
df <- df %>% 
  mutate(name = case_when(
    name == "ESS1e06_7" ~ "2002",
    name == "ESS2e03_6" ~ "2004",
    name == "ESS3e03_7" ~ "2006",
    name == "ESS4e04_6" ~ "2008",
    name == "ESS5e03_5" ~ "2010",
    name == "ESS6e02_6" ~ "2012",
    name == "ESS7e02_3" ~ "2014",
    name == "ESS8e02_3" ~ "2016",
    name == "ESS9e03_2" ~ "2018",
    name == "ESS10e03_2" ~ "2020",
    name == "ESS10SCe03_1" ~ "2020",
    name == "ESS11e02" ~ "2023"
  ))
dfhappy2023 <- df %>% 
  filter(name == "2023") %>% 
  select(cntry, happy) %>% 
  filter(happy <= 10) %>% 
  group_by(cntry, happy) %>% 
  summarise(qty = n(), .groups = "drop") %>% 
  group_by(cntry) %>% 
  mutate(perc = round((qty / sum(qty)) * 100, 1)) %>% 
    mutate(accum_freq = cumsum(perc)) %>% 
  mutate(accum_freq = ifelse(row_number() == n(), 100, accum_freq)) # Set last row to 100

dfhappy2023
plot <- dfhappy2023 %>%
  plot_ly(
    #x = ~happy,
    #y = ~perc,
    y = ~happy,
    x = ~perc,
    color = ~cntry,
    type = 'scatter',
    #mode = 'lines',
    mode = 'lines+markers',
    #fill = 'tonexty', # Fills area below the line
    text = ~paste("Country:", cntry, "<br>Happy:", happy, "<br>Percentage:", perc, "%")
  ) %>%
  layout(
    title = "Distribution of Happiness Scores by Country in 2023",
    xaxis = list(title = "Happiness Score", tickvals = 0:100),
    yaxis = list(title = "Percentage"),
    legend = list(title = list(text = "Country"))
  )

plot
Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors

Warning in RColorBrewer::brewer.pal(N, "Set2") :
  n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
unique(dfhappy$cntry)
 [1] "BE" "CH" "DE" "ES" "FI" "FR" "GB" "HU" "IE" "NL" "NO" "PL" "PT" "SE" "SI"

plot <- dfhappy2023 %>%
  plot_ly(
    x = ~cntry, # Percentages on the x-axis
    y = ~perc, # Countries on the y-axis
    color = ~happy, # Color by level of happiness
    type = 'bar', # Bar chart
    #orientation = 'h', # Horizontal bars
    #text = ~paste("Country:", cntry, "<br>Happy Level:", happy, "<br>Percentage:", perc, "%"),
    #hoverinfo = 'text' # Custom hover info
    text = ~happy, # Display only happiness level on the graph
    hoverinfo = 'text', # Maintain hover information
    hovertext = ~paste("Country:", cntry, "<br>Happy Level:", happy, "<br>Percentage:", perc, "%") # Detailed hover info
  ) %>%
  layout(
    barmode = 'stack', # Stacked bars
    title = "Happiness Distribution by Level Across Countries (2023)",
    xaxis = list(title = "Percentage"),
    yaxis = list(title = "Country"),
    legend = list(title = list(text = "Happiness Level"))
  )

plot
Warning: textfont.color doesn't (yet) support data arrays
Warning: textfont.color doesn't (yet) support data arrays
Warning: textfont.color doesn't (yet) support data arrays
Warning: textfont.color doesn't (yet) support data arrays
op_cntry1 <- 'NL'
op_cntry2 <- 'PT'

op_df <- dfhappy2023 %>% 
  filter(cntry == op_cntry1 | cntry == op_cntry2 | cntry == 'HU' | cntry == 'FR') %>% 
  mutate(accum_freq = cumsum(perc)) %>% 
  mutate(accum_freq = ifelse(row_number() == n(), 100, accum_freq)) # Set last row to 100

op_df

# Create the Plotly graph
plot <- op_df %>%
  plot_ly(
    x = ~happy,                # Happiness levels as the x-axis
    y = ~perc,                 # Percentage values as the y-axis
    color = ~cntry,            # Different colors for each country
    type = 'bar',              # Bar chart type
    barmode = 'group',         # Grouped bars (side-by-side)
    text = ~paste(
      "Country:", cntry, 
      "<br>Happiness score:", happy, 
      "<br>Percentage:", perc, "%",
      "<br>Accumulated Frequency:", accum_freq, "%"
    ),                         # Hover information with details
    hoverinfo = 'text'         # Enable hover with custom text
  ) %>%
  layout(
    title = "Happiness Levels by Country",     # Chart title
    xaxis = list(title = "Happiness Level"),   # X-axis label
    yaxis = list(title = "Percentage"),        # Y-axis label
    legend = list(title = list(text = "Country")) # Legend title
  )

plot
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
plot <- plot_ly() %>%
  add_trace(
    data = op_df,
    x = ~happy,
    y = ~perc,
    color = ~cntry,
    type = 'bar',
    barmode = 'group',
    #name = 'Percentage',
    text = ~paste0(
      "Country:", cntry, 
      "<br>Happiness Score:", happy, 
      "<br>Percentage:", perc, "%",
      "<br>Accumulated Frequency:", accum_freq, "%"),  # Hover information with details
    hoverinfo = 'text', textposition = 'none') %>%   # Enable hover with custom text

  add_trace(
    data = op_df,
    x = ~happy,
    y = ~accum_freq,
    color = ~cntry,
    type = 'scatter',
    mode = 'lines+markers',
    #name = 'Cumulative Frequency',
    text = ~paste("Country:", cntry, 
      "<br>Happy Level:", happy, 
      "<br>Percentage:", perc, "%",
      "<br>Accumulated Frequency:", accum_freq, "%"),  # Hover information with details
    hoverinfo = 'text', textposition = 'none') %>% 

  layout(
    title = "Grouped Bar Chart with Cumulative Line",
    xaxis = list(title = "Happiness Scores"),
    yaxis = list(title = "Percentage"),
    legend = list(title = list(text = "Country"))
  )

plot
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
Warning: 'bar' objects don't have these attributes: 'barmode'
Valid attributes include:
'_deprecated', 'alignmentgroup', 'base', 'basesrc', 'cliponaxis', 'constraintext', 'customdata', 'customdatasrc', 'dx', 'dy', 'error_x', 'error_y', 'hoverinfo', 'hoverinfosrc', 'hoverlabel', 'hovertemplate', 'hovertemplatesrc', 'hovertext', 'hovertextsrc', 'ids', 'idssrc', 'insidetextanchor', 'insidetextfont', 'legendgroup', 'legendgrouptitle', 'legendrank', 'marker', 'meta', 'metasrc', 'name', 'offset', 'offsetgroup', 'offsetsrc', 'opacity', 'orientation', 'outsidetextfont', 'selected', 'selectedpoints', 'showlegend', 'stream', 'text', 'textangle', 'textfont', 'textposition', 'textpositionsrc', 'textsrc', 'texttemplate', 'texttemplatesrc', 'transforms', 'type', 'uid', 'uirevision', 'unselected', 'visible', 'width', 'widthsrc', 'x', 'x0', 'xaxis', 'xcalendar', 'xhoverformat', 'xperiod', 'xperiod0', 'xperiodalignment', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'yhoverformat', 'yperiod', 'yperiod0', 'yperiodali [... truncated]
df <- read.csv("Data/ess_allyr_multi.csv")

df <- df %>%
  mutate(name = case_when(
    name == "ESS1e06_7" ~ "2002",
    name == "ESS2e03_6" ~ "2004",
    name == "ESS3e03_7" ~ "2006",
    name == "ESS4e04_6" ~ "2008",
    name == "ESS5e03_5" ~ "2010",
    name == "ESS6e02_6" ~ "2012",
    name == "ESS7e02_3" ~ "2014",
    name == "ESS8e02_3" ~ "2016",
    name == "ESS9e03_2" ~ "2018",
    name == "ESS10e03_2" ~ "2020",
    name == "ESS10SCe03_1" ~ "2020",
    name == "ESS11e02" ~ "2023"
  ))


dfhappy <- df %>%
  select(name, cntry, happy) %>%
  filter(happy <= 10) %>%
  group_by(name, cntry, happy) %>% 
  summarise(qty = n(), .groups = "drop") %>%
  group_by(name, cntry) %>%
  mutate(perc = round((qty / sum(qty)) * 100, 1))
filtered <- dfhappy %>%
      filter(cntry == c('NL', 'PT'), name == '2023') %>%
      group_by(cntry) %>%
      mutate(accum_freq = cumsum(perc)) %>%
      mutate(accum_freq = ifelse(row_number() == n(), 100, accum_freq)) # Ensure last value = 100
    
    # Calculate metrics relative to happiness level 5
metrics <- filtered %>%
      filter(happy == 5) %>%
      mutate(towards_unhappy = accum_freq,
        towards_happy = 100 - accum_freq)
    
  metrics
plot_ly(data = happy_health, x = ~happy_health$happy) #, y = ~happy_health$health)
No trace type specified:
  Based on info supplied, a 'histogram' trace seems appropriate.
  Read more about this trace type -> https://plotly.com/r/reference/#histogram
No trace type specified:
  Based on info supplied, a 'histogram' trace seems appropriate.
  Read more about this trace type -> https://plotly.com/r/reference/#histogram
NA
LS0tDQp0aXRsZTogIlIgTm90ZWJvb2siDQpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sNCi0tLQ0KDQpUaGlzIGlzIGFuIFtSIE1hcmtkb3duXShodHRwOi8vcm1hcmtkb3duLnJzdHVkaW8uY29tKSBOb3RlYm9vay4gV2hlbiB5b3UgZXhlY3V0ZSBjb2RlIHdpdGhpbiB0aGUgbm90ZWJvb2ssIHRoZSByZXN1bHRzIGFwcGVhciBiZW5lYXRoIHRoZSBjb2RlLiANCg0KVHJ5IGV4ZWN1dGluZyB0aGlzIGNodW5rIGJ5IGNsaWNraW5nIHRoZSAqUnVuKiBidXR0b24gd2l0aGluIHRoZSBjaHVuayBvciBieSBwbGFjaW5nIHlvdXIgY3Vyc29yIGluc2lkZSBpdCBhbmQgcHJlc3NpbmcgKkN0cmwrU2hpZnQrRW50ZXIqLiANCg0KYGBge3J9DQpsaWJyYXJ5KGNhcikNCmBgYA0KDQoNCmBgYHtyfQ0KZGYgPC0gcmVhZC5jc3YoIkRhdGEvZGZfY2xlYW5fbW9yZV9mZWF0dXJlcy5jc3YiKQ0KDQpnZXR2YXIgPC0gZnVuY3Rpb24oKQ0KDQpkZnVrIDwtIGRmW2RmJGNudHJ5ID09ICJVbml0ZWQgS2luZ2RvbSIsIF0NCmB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